﻿using System;
using System.Collections;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Connection;
using Me.Prettyprint.Cassandra.Serializers;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Query;
using Org.Apache.Cassandra.Thrift;

namespace Me.Prettyprint.Cassandra.Model
{
    /// <summary>
    /// Default implementation of CounterSuperSlice converts thrift
    /// CounterSuperColumn to hector CounterSuperSlice.
    /// </summary>
    /// <typeparam name="SN"></typeparam>
    /// <typeparam name="N"></typeparam>
    public class CounterSuperSliceImpl<SN, N> : CounterSuperSlice<SN,N>
    {
        public CounterSuperSliceImpl(List<CounterSuperColumn> tSuperColumns, Serializer<SN> sNameSerializer,
            Serializer<N> nameSerializer)
        {
            if (tSuperColumns == null || sNameSerializer == null || nameSerializer == null)
            {
                throw new NullReferenceException("Super columns, supername serializer and name serializer cannot be null");
            }
            ColumnsDictionary = new Dictionary<SN, HCounterSuperColumn<SN, N>>(tSuperColumns.Count);
            ColumnsList = new List<HCounterSuperColumn<SN,N>>(tSuperColumns.Count);
            foreach (CounterSuperColumn sc in tSuperColumns)
            {
                HCounterSuperColumn<SN,N> column = new HCounterSuperColumnImpl<SN,N>(sc, sNameSerializer, nameSerializer);
                ColumnsDictionary[column.Name] = column;
                ColumnsList.Add(column);
            }
        }
        protected Serializer<SN> SuperNameSerializer
        {
            get;
            set;
        }
        protected Serializer<N> NameSerializer
        {
            get;
            set;
        }
        protected Dictionary<SN,HCounterSuperColumn<SN,N>> ColumnsDictionary
        {
            get;
            set;
        }
        private List<HCounterSuperColumn<SN, N>> ColumnsList
        {
            get;
            set;
        }
        public List<HCounterSuperColumn<SN,N>> GetSuperColumns()
        {
            return ColumnsList;
        }
        public HCounterSuperColumn<SN, N> GetColumnByName(SN columnName)
        {
            return ColumnsDictionary[columnName];
        }
        public override string ToString()
        {
            return "SuperSlice(" + ColumnsList.ToString() + ")";
        }
    }
}
